/*     */ package com.zimbra.cs.redolog.op;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.cs.mailbox.MailItem.TargetConstraint;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.MailboxOperation;
/*     */ import com.zimbra.cs.redolog.RedoLogInput;
/*     */ import com.zimbra.cs.redolog.RedoLogOutput;
/*     */ import java.io.IOException;
/*     */ import java.util.Arrays;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class DeleteItem
/*     */   extends RedoableOp
/*     */ {
/*     */   private int[] mIds;
/*     */   private MailItem.Type type;
/*     */   private String mConstraint;
/*     */   
/*     */   public DeleteItem()
/*     */   {
/*  42 */     super(MailboxOperation.DeleteItem);
/*  43 */     this.type = MailItem.Type.UNKNOWN;
/*  44 */     this.mConstraint = null;
/*     */   }
/*     */   
/*     */   public DeleteItem(int mailboxId, int[] ids, MailItem.Type type, MailItem.TargetConstraint tcon) {
/*  48 */     this();
/*  49 */     setMailboxId(mailboxId);
/*  50 */     this.mIds = ids;
/*  51 */     this.type = type;
/*  52 */     this.mConstraint = (tcon == null ? null : tcon.toString());
/*     */   }
/*     */   
/*     */   public DeleteItem(int mailboxId, MailItem.Type type, MailItem.TargetConstraint tcon) {
/*  56 */     this(mailboxId, null, type, tcon);
/*     */   }
/*     */   
/*     */   public void setIds(int[] ids) {
/*  60 */     this.mIds = ids;
/*     */   }
/*     */   
/*     */   protected String getPrintableData()
/*     */   {
/*  65 */     StringBuilder sb = new StringBuilder("ids=");
/*  66 */     sb.append(Arrays.toString(this.mIds)).append(", type=").append(this.type);
/*  67 */     if (this.mConstraint != null) {
/*  68 */       sb.append(", constraint=").append(this.mConstraint);
/*     */     }
/*  70 */     return sb.toString();
/*     */   }
/*     */   
/*     */   protected void serializeData(RedoLogOutput out) throws IOException
/*     */   {
/*  75 */     out.writeInt(-1);
/*  76 */     out.writeByte(this.type.toByte());
/*  77 */     boolean hasConstraint = this.mConstraint != null;
/*  78 */     out.writeBoolean(hasConstraint);
/*  79 */     if (hasConstraint) {
/*  80 */       out.writeUTF(this.mConstraint);
/*     */     }
/*  82 */     out.writeInt(this.mIds.length);
/*  83 */     for (int id : this.mIds) {
/*  84 */       out.writeInt(id);
/*     */     }
/*     */   }
/*     */   
/*     */   protected void deserializeData(RedoLogInput in) throws IOException
/*     */   {
/*  90 */     int id = in.readInt();
/*  91 */     if (id > 0) {
/*  92 */       this.mIds = new int[] { id };
/*     */     }
/*  94 */     this.type = MailItem.Type.of(in.readByte());
/*  95 */     if (in.readBoolean()) {
/*  96 */       this.mConstraint = in.readUTF();
/*     */     }
/*  98 */     if (id <= 0) {
/*  99 */       this.mIds = new int[in.readInt()];
/* 100 */       for (int i = 0; i < this.mIds.length; i++) {
/* 101 */         this.mIds[i] = in.readInt();
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void redo() throws Exception
/*     */   {
/* 108 */     int mboxId = getMailboxId();
/* 109 */     Mailbox mbox = MailboxManager.getInstance().getMailboxById(mboxId);
/*     */     
/* 111 */     MailItem.TargetConstraint tcon = null;
/* 112 */     if (this.mConstraint != null) {
/*     */       try {
/* 114 */         tcon = MailItem.TargetConstraint.parseConstraint(mbox, this.mConstraint);
/*     */       } catch (ServiceException e) {
/* 116 */         mLog.warn(e);
/*     */       }
/*     */     }
/*     */     try {
/* 120 */       mbox.delete(getOperationContext(), this.mIds, this.type, tcon);
/*     */     } catch (MailServiceException.NoSuchItemException e) {
/* 122 */       if (mLog.isInfoEnabled()) {
/* 123 */         mLog.info("Some of the items being deleted were already deleted from mailbox " + mboxId);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public boolean isDeleteOp()
/*     */   {
/* 130 */     return true;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/DeleteItem.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */